package com.itheima.mapper;

import com.itheima.pojo.Order;
import com.itheima.pojo.User;
import com.itheima.pojo.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapperMoreTable {

    //通过id查询用户的扩展信息
    @Select("SELECT *FROM USER WHERE user.id=#{uid};")
    @Results({
            @Result(property = "id",column = "id",id = true),
            @Result(property = "id2",column = "id_2"),
            @Result(property = "username",column = "username"),
            @Result(property = "birthday",column = "birthday"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "address", column = "address"),
            @Result(property = "userInfo",column = "id",one = @One(select = "findUserInfo")),
            @Result(property = "orders",column = "id_2",many = @Many(select = "findOrders"))
    })
    User findUserById(int uid);

    @Select("SELECT *FROM user_info WHERE id = #{uid};")
    UserInfo findUserInfo(int uid);


    @Select("SELECT *FROM `order` WHERE user_id =#{uid};")
    List<Order> findOrders(int uid);
}
